package com.spc.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.spc.entity.PageResult;
import com.spc.entity.QueryPageBean;
import com.spc.entity.Result;
import com.spc.pojo.Address;
import com.spc.service.MapService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/map")
public class MapController {
    @Reference
    private MapService mapService;

    //地址查询
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Address> list = mapService.findAll();
            return new Result(true,"",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"获取失败");
        }
    }

    //地址分页查项
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){

        PageResult pageResult = mapService.findPage(queryPageBean);

        return pageResult;
    }

    //地址分页查项
    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            mapService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除地址失败");
        }

        return new Result(true,"删除地址成功");
    }

    //地址分页查项
    @RequestMapping("/add")
    public Result add(@RequestBody Address address){
        try {
            mapService.add(address);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加失败");
        }

        return new Result(true,"添加成功");
    }
}
